package com.awan.ui;

import com.beem.project.beem.R;
import com.beem.project.beem.ui.Chat;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

public class LoadMedia extends Activity{
	Context ctx;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		ctx=this;
		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Bundle b=getIntent().getBundleExtra("media_data");
		if(b!=null){
			final String dataValue = b.getString("fileurl");
			final boolean isLocalFile = b.getBoolean("islocal");
			if(dataValue != null){
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						// TODO Auto-generated method stub
						if(isLocalFile){
							Intent browserIntent = new Intent(Intent.ACTION_VIEW);
							String dataType = "";
							if(dataValue.contains(".3gp"))
								dataType = "video/*";
							else
								dataType = "image/*";
							//Log.e(getClass().getSimpleName(), "dataValue:"+dataValue+" \ndataType : "+dataType);
							browserIntent.setDataAndType(Uri.parse(dataValue),dataType);
							ctx.startActivity(browserIntent);
						}else{
							//Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(dataValue));
							//startActivity(browserIntent);
							AlertDialog.Builder chargeDialogBuilder;   
					        Context mContext = LoadMedia.this;   
					        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);   
					        View chargeLayout = inflater.inflate(R.layout.charge_popup,(ViewGroup) findViewById(R.id.chargeWebView));
					        
					        final WebView chargeWebView = (WebView)chargeLayout.findViewById(R.id.chargeWebView);
					        chargeDialogBuilder = new AlertDialog.Builder(mContext);  
					       // chargeDialogBuilder.setTitle("Sticker Charge Page");
					        chargeDialogBuilder.setView(chargeLayout);   
					        final Dialog chargeDialog = chargeDialogBuilder.create();
					        chargeDialog.show();
					        chargeWebView.loadUrl(dataValue);
						}
					}
				});
			}
			finish();
		}else{
			finish();
		}
	}
	private void imageLoader(){
		
	}
}
